package com.bwie.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.demo.mapper.ConsmeticMapper;
import com.bwie.demo.mapper.DetailsMapper;
import com.bwie.demo.model.Consmetic;
import com.bwie.demo.model.Details;
import com.bwie.demo.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @use ConsmeticService
 * @Author yp
 * @Date 2020-11-30-9:16
 */
@Service
public class ConsmeticService {
    /**
     * 注入化妆品系列的接口实现
     */
    @Autowired
    private ConsmeticMapper consmeticMapper;
    /**
     * 注入化妆品详情的接口实现
     */
    @Autowired
    private DetailsMapper detailsMapper;

    /**
     * 查询,分页,排序一条龙
     * @param page 当前页
     * @param size 每页显示数
     * @param searchMap 模糊查询
     * @return list
     */
    public PageResult findPage(int page, int size, Map searchMap){
        QueryWrapper<Consmetic> queryWrapper = new QueryWrapper();
        if (searchMap.get("csSeries") != null&& !"".equals(searchMap.get("csSeries"))){
            queryWrapper.lambda().like(Consmetic::getCsSeries,searchMap.get("csSeries"));
        }
        Page<Consmetic> pages = consmeticMapper.selectPage(new Page<>(page, size), queryWrapper);
        return new PageResult(pages.getTotal(),pages.getRecords());
    }

    /**
     * 根据详情id 查询详情
     * @param id 他的id
     * @return Details
     */
    public Details findById(Integer id){
        //调用查询id的方法
        return detailsMapper.selectById(id);
    }

    /**
     * 修改状态
     * @param id
     */
    public void update(Integer id){
        detailsMapper.updateRole(id);
    }
}
